from exts import db
from models import AdminModel, BorrowerModel, BookModel, Book_statusModel, Book_styleModel


def Create_data():
    # 生成数据
    # db.drop_all()
    # db.create_all()
    # 管理员
    A1 = AdminModel(name='admin', password='123456', email='2569535507@qq.com')
    db.session.add(A1)
    db.session.commit()

    # 图书类型
    E1 = Book_styleModel(type_id=1001, type_name="计算机")
    E2 = Book_styleModel(type_id=1002, type_name="自然科学")
    db.session.add_all([E1, E2])
    db.session.commit()
    # 图书信息
    B1 = BookModel(book_id='10001', book_name='C++ primer', book_author='张三', book_type='计算机', book_publish='浙江大学出版社',
                   book_publish_time=2002, book_price=20,
                   book_amount=20, book_stock=15)
    B2 = BookModel(book_id='10002', book_name='python', book_author='李四', book_type='自然科学', book_publish='北京大学出版社',
                   book_publish_time=2021, book_price=44,
                   book_amount=24, book_stock=13)
    B3 = BookModel(book_id='10003', book_name='java', book_author='王五', book_type='计算机', book_publish='电子工业出版社',
                   book_publish_time=2019, book_price=76,
                   book_amount=4, book_stock=4)
    db.session.add_all([B1, B2, B3])
    db.session.commit()
    # 借阅者
    C1 = BorrowerModel(name='zhangsan', password='123',phone="11111",email="asdasd")
    C2 = BorrowerModel(name='lisi', password='122',phone="1ad1",email="asdfsd")
    db.session.add_all([C1, C2])
    db.session.commit()
    # 借阅信息
    D1 = Book_statusModel(book_id='10001', book_name="C++ primer", borrower_name='zhangsan')
    db.session.add(D1)
    db.session.commit()
